package handler

import (
	exam "exam_srv/proto"
	"flag"
	"go.uber.org/zap"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	paper "test_paper_srv/proto"
	question "test_question_srv/proto"
	user "user_srv/proto"
)

type ServerInterface interface {
	UserServer(addr *string) user.UserClient
	QuestionServer(addr *string) question.QuestionClient
	PaperServer(addr *string) paper.PaperClient
	ExamServer(addr *string) exam.ExamClient
}

type ServerConfig struct {
}

func NewClient() *ServerConfig {
	return &ServerConfig{}
}

func Init(addr *string) *grpc.ClientConn {
	flag.Parse()
	con, err := grpc.NewClient(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		zap.S().Error(err.Error())
	}
	return con
}

func (c ServerConfig) UserServer(addr *string) user.UserClient {
	init := Init(addr)
	client := user.NewUserClient(init)
	return client
}

func (c ServerConfig) QuestionServer(addr *string) question.QuestionClient {
	init := Init(addr)
	client := question.NewQuestionClient(init)
	return client
}

func (c ServerConfig) PaperServer(addr *string) paper.PaperClient {
	init := Init(addr)
	client := paper.NewPaperClient(init)
	return client
}

func (c ServerConfig) ExamServer(addr *string) exam.ExamClient {
	init := Init(addr)
	client := exam.NewExamClient(init)
	return client
}
